﻿
namespace HSS.Xaml.UI.Data
{
	#region Using Directives
	using System;
	using System.Globalization;
	using System.Windows.Data;
	using HSS.ComponentModel;
	#endregion

	#region EnumValueConverter
	/// <summary>
	/// Converts an Enum value to and from a <see cref="String"/>.
	/// </summary>
	public class EnumValueConverter : IValueConverter
	{
		/// <summary>
		/// Convert to a string
		/// </summary>
		/// <param name="value"></param>
		/// <param name="targetType"></param>
		/// <param name="parameter"></param>
		/// <param name="culture"></param>
		/// <returns></returns>
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			Guard.ArgumentNotNull(value, "value");
			return new EnumConverter(value.GetType()).ConvertTo(value, targetType);
		}
		/// <summary>
		/// Convert from a string
		/// </summary>
		/// <param name="value"></param>
		/// <param name="targetType"></param>
		/// <param name="parameter"></param>
		/// <param name="culture"></param>
		/// <returns></returns>
		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return new EnumConverter(targetType).ConvertFrom(value);
		}
	}
	#endregion
}
